// pages/myHelp/myHelp.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageUrl: 'https://armeco.happydoit.com/upload', // 服务器图片路径
    historyList: [], //历史记录
    cups: 0, // 已收集数量
    cityName: '', //芯愿城市
    cityId: -1, //芯愿城市id
    userInfo: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.getInfo();
    that.setData({
      cityName: options.cityName,
      cityId: options.cityId,
      canFocus: app.globalData.canFocus,
      userInfo: app.globalData.userInfo
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    let that = this;
    return {
      title: '让邓伦来我的芯愿城市，就靠你的助力了！',
      path: '/pages/stage/shareHelp/shareHelp?cityName=' + that.data.cityName + '&&cityId=' + that.data.cityId + '&&userid=' + that.data.userInfo.id,
      imageUrl: that.data.imageUrl + '/cityimages/share-img.png'
    }
  },

  // 返回上一页
  back: function () {
    wx.navigateBack({
      delta: 1
    });
  },

  // 前往扫码助力页面
  toScanCode: function () {
    wx.navigateTo({
      url: '/pages/heloo/index/index'
    });
  },

  // 获取个人助力信息
  getInfo: function () {
    let that = this;
    wx.showLoading({
        title: '加载中',
        mask: true,
    });
    wx.request({
        url: app.globalData.requestUrl + '/api/city/couldUseCupsPage',
        data: {},
        method: "POST",
        header: {
            "Content-Type": "application/x-www-form-urlencoded",
            "Cookie": "JSESSIONID=" + app.globalData.jessionId
        },
        success: function (res) {
            if (res.data.code == 'success') {
                wx.hideLoading();
                that.setData({
                  historyList: res.data.data.list,
                  cups: res.data.data.couldusecups
                })
            } else {
                wx.hideLoading();
                wx.showToast({
                    title: res.data.msg,
                    icon: 'none',
                    mask: true
                })
            }
        }
    })
  },

  showFocus() {
    this.setData({
      isFocus: true
    })
  },

  hideFocus() {
    this.setData({
      isFocus: false
    })
  },

  openRule() {
    this.setData({
      showRule: true
    })
  },

  onGetCode: function (e) {
    this.setData({
      showRule: e.detail.val
    })
  }
})